import { defineStore } from "pinia"
import { computed, ref } from 'vue'

// 选项式写法
/* export const useNormalStore = defineStore('normal', {
  state() {
    let talkList: Array<{ message: string }> = []
    talkList = JSON.parse(localStorage.getItem('talkList') as string) || []
    return {
      totalNum: 0,
      schoolName: "何苦中学",
      teacherName: "李老师",

      talkList: talkList
    }
  },
  actions: {
    changeTotalNum(value: number) {
      this.totalNum = value
    },
  },
  getters: {
    schoolTeacher(state):string {
      return `${state.schoolName} -- ${this.teacherName}`
    }
  }
})
 */

// 组合式写法
export const useNormalStore = defineStore('normal', () => {
  let talkList = ref<Array<{message: string }>>(JSON.parse(localStorage.getItem('talkList') as string) || [])
  let totalNum = ref(0)
  let schoolName = ref("何苦中学")
  let teacherName = ref("李老师")

  function changeTotalNum(value: number) {
    totalNum.value = value
  }
  let schoolTeacher = computed(() => {
    return `${schoolName.value} -- ${teacherName.value}`
  })
  return { talkList, totalNum, schoolName, teacherName, schoolTeacher, changeTotalNum }
})
